*******************************************************************************
******************************  FIGURE 4  *************************************
******************* Global Assessments Over Time ******************************
*******************************************************************************

clear all
set more off

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_4"

*ssc install outreg2, replace

********************************************************************************

***Figure 4a***

use "figure_4_dataset_1.dta", clear
foreach var of varlist femvotesminfl_s2_ratio femvotesminfl_s3_ratio {
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	outreg2 margins using "intermediate_data/study2_`var'", replace dta side noparen noas
}

foreach var of varlist femvotesminfl_s4_ratio femvotesminfl_s5_ratio {
	reg `var' i.condition_2f if fem_leader == 1, robust
	margins condition_2f, post
	estimates store margins
	outreg2 margins using "intermediate_data/study2_`var'_femleader", replace dta side noparen noas
	
	reg `var' i.condition_2f if fem_leader == 0, robust
	margins condition_2f, post
	estimates store margins
	outreg2 margins using "intermediate_data/study2_`var'_maleleader", replace dta side noparen noas
}

use "intermediate_data/study2_femvotesminfl_s2_ratio_dta.dta", clear
	gen month = 1
append using "intermediate_data/study2_femvotesminfl_s3_ratio_dta.dta"
	replace month = 2 if month==.
append using "intermediate_data/study2_femvotesminfl_s4_ratio_femleader_dta.dta"
	gen leader = "Female" if month==.
	replace month = 3 if month==.
append using "intermediate_data/study2_femvotesminfl_s4_ratio_maleleader_dta.dta"
	replace leader = "Male" if month==.
	replace month = 3 if month==.
append using "intermediate_data/study2_femvotesminfl_s5_ratio_femleader_dta.dta"
	replace leader = "Female" if month==.
	replace month = 4 if month==.
append using "intermediate_data/study2_femvotesminfl_s5_ratio_maleleader_dta.dta"
	replace leader = "Male" if month==.
	replace month = 4 if month==.
	
	drop if v1==""
	drop if v1=="VARIABLES"
	drop if v1=="Observations"
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	destring v3 v2, replace
	ren v1 condition
	ren v2 estimate
	ren v3 stderr
	gen ci=stderr*1.96
	
	expand 3 in 3
	replace leader = "Male" in 13
	replace leader = "Female" in 14
	expand 3 in 4
	replace leader = "Male" in 15
	replace leader = "Female" in 16
	replace leader = "Before Leader Assignment" if leader == ""
	
	gen condition_leader = condition + ", " + leader + " Leader"
	replace condition_leader = condition if leader==""
	sort month condition_leader
	
export delimited "intermediate_data/study2_femvotesminfl_bymonth_forgraphing.csv", replace

***Figure 4b***
use "figure_4_dataset_2.dta", clear

foreach var of varlist genderminfl_sep_ratio genderminfl_oct_ratio genderminfl_nov_ratio genderminfl_dec_ratio {
reg `var' i.fall_condition
	margins fall_condition, post
	estimates store margins
outreg2 margins using "intermediate_data/`var'", replace dta side noparen noas
}

	*surveys
use "intermediate_data/genderminfl_sep_ratio_dta.dta", clear
	gen month = "1"
append using "intermediate_data/genderminfl_oct_ratio_dta.dta"
	replace month = "2" if month==""
append using "intermediate_data/genderminfl_nov_ratio_dta.dta"
	replace month = "3" if month==""
append using "intermediate_data/genderminfl_dec_ratio_dta.dta"
	replace month = "4" if month==""
	drop if v1==""
	drop if v1=="VARIABLES"
	drop if v1=="Observations"
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	destring v3 v2, replace
	ren v1 condition
	ren v2 estimate
	ren v3 stderr
	gen ci=stderr*1.96
export delimited "intermediate_data/surveyminfl_bymonth_forgraphing.csv", replace






